<?php

class SnoopyController extends Controller
{
	/**
	 * 查询物流跟踪
	 */
	public function actionExpress()
	{
		$typeCom = $_GET ["com"]; // 快递公司
		$typeNu = $_GET ["nu"]; // 快递单号

		$AppKey = '8d84829016110445'; // 请将XXXXXX替换成您在http://kuaidi100.com/app/reg.html申请到的KEY
		if($typeCom=='ems'||$typeCom=='shentong'||$typeCom=='shunfeng'){
			$url = 'http://www.kuaidi100.com/applyurl?key=' . $AppKey . '&com=' . $typeCom . '&nu=' . $typeNu . '';
		}else{
			$url = 'http://api.kuaidi100.com/api?id=' . $AppKey . '&com=' . $typeCom . '&nu=' . $typeNu . '&show=2&muti=1&order=asc';
		}
		
		// 请勿删除变量$powered 的信息，否者本站将不再为你提供快递接口服务。
		$powered = Yii::t( "exp_api", 'msg' );
		
		// 优先使用curl模式发送数据
		if (function_exists ( 'curl_init' ) == 1) {
			$curl = curl_init ();
			curl_setopt ( $curl, CURLOPT_URL, $url );
			curl_setopt ( $curl, CURLOPT_HEADER, 0 );
			curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
			curl_setopt ( $curl, CURLOPT_USERAGENT, $_SERVER ['HTTP_USER_AGENT'] );
			curl_setopt ( $curl, CURLOPT_TIMEOUT, 5 );
			$get_content = curl_exec ( $curl );
			curl_close ( $curl );
		} else {
			$snoopy = new snoopy ();
			$snoopy->referer = 'http://www.google.com/'; // 伪装来源
			$snoopy->fetch ( $url );
			$get_content = $snoopy->results;
		}
		if (preg_match('/http:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is',$get_content))
		{
			$expinfo = "<iframe src='".$get_content."' width='550' height='350' frameborder='0' scrolling='no' ></iframe>";
		}else{
			$expinfo = $get_content . '<br/>' . $powered;
		}
		print_r ( $expinfo );
	}

}